package com.fenghongzhang.homework.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;

import com.fasterxml.jackson.databind.annotation.JsonAppend.Prop;

import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2
//@Profile("dev") //只在开发环境启用
public class Swagger2Config {
	 /**
     * 对所有api扫描配置:controller路径
     */
    private static final String BASE_PACKAGE = "com.fenghongzhang";
	
	@Bean
	public Docket createRestApi() {
		return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo()) //下面的api方法
                .select()
                .apis(RequestHandlerSelectors.basePackage(BASE_PACKAGE)) //api接口包扫描路径
                .paths(PathSelectors.any()) //可以根据url路径设置哪些请求加入文档，忽略哪些请求
                .build();
	}
	
	
	private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
        		 //页面标题
                .title("Spring mvc 测试使用 Swagger2 构建Api") //标题
                .description("推荐RestFul风格") //对这个项目的描述
                .termsOfServiceUrl("https://www.fenghongzhang.com/") //这个项目的服务地址
                .version("1.0")  //自己api的版本号.
                .build();
    }

}
